<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    <script src="js/mui.min.js"></script>
    <link href="css/mui.min.css" rel="stylesheet"/>

</head>
<body>
	<header class="mui-bar mui-bar-nav">
		<a class="mui-icon mui-action-menu mui-icon-arrowleft mui-pull-left" onclick="mui.back()"></a>
		<h1 class="mui-title ">注册</h1>
	</header>
	
	<div class="mui-content">
	</div>
	
	<div class="mui-input-row">
	    <label>账号</label>
	    <input id="user_name" type="text" class="mui-input-clear" placeholder="账号名">
	</div>
	<div class="mui-input-row">
	    <label>实名(老师看见的)</label>
	    <input id="r_name" type="text" class="mui-input-clear" placeholder="实名(老师看见的)">
	</div>
	<div class="mui-input-row">
	    <label>密码</label>
	    <input id="password" type="password" class="mui-input-clear" placeholder="密码">
	</div>
	<div class="mui-input-row">
	    <label>确认密码</label>
	    <input id="password_ok" type="password" class="mui-input-clear" placeholder="确认密码">
	</div>

	
	<div class="mui-row">
	    <button id='login' class="mui-btn mui-btn-block mui-btn-primary" onclick="reg()">注册</button>
	</div>
	<script type="text/javascript" charset="utf-8">
	  	mui.init();
		mui.plusReady(function () {
		    
		})
		document.addEventListener("plusready", function() {
			// 页面加载完成后自动执行
		});
		function reg(){
			var user_name = document.getElementById("user_name").value;
			var password = document.getElementById("password").value;
			var password_ok = document.getElementById("password_ok").value;
			var r_name = document.getElementById("r_name").value;
			var url = plus.storage.getItem("rw_server")+"register"
			if(user_name == "" || password == "" || password_ok == "" || r_name == ""){
				mui.toast("请输入完整信息");
				return;
			}
			if(password != password_ok){
				mui.toast("两次密码不一致");
				return;
			}
			fetch(url,{
			    method: "post",
			    headers: {
			        "Content-Type": "application/json"
			    },
			    body: JSON.stringify({
			        "user_id": user_name,
			        "real_name": password,
					"password": password,
			    })
			})
			.then(res => res.text())
			.then(res => {
				if(res == "创建成功"){
					mui.toast("创建成功");
					mui.back();
				}else{
					mui.toast("注册失败");
					
				}
			})
			}
	</script>

</body>
</html>